/**
 *
 * @author zzhijie
 * @date 2020-10-23
 */
import Vue from 'vue';

export function getInstance(component, options) {
  let Constructor = Vue.extend(component);
  let instance = new Constructor(options);
  instance.$mount();
  document.body.appendChild(instance.$el);
  return instance;
}

export function getScroller(el, root = window) {
  let overflowScrollReg = /scroll|auto/i;
  let node = el;
  while (
    node &&
    node.tagName !== 'HTML' &&
    node.tagName !== 'BODY' &&
    node.nodeType === 1 &&
    node !== root
    ) {
    const {overflowY} = window.getComputedStyle(node);
    if (overflowScrollReg.test(overflowY)) {
      return node;
    }
    node = node.parentNode;
  }
  return root;
}

export function getDirection(x, y) {
  if (x > y) {
    return 'horizontal';
  }
  if (y > x) {
    return 'vertical';
  }
  return '';
}
